<%@page import="com.alibaba.fastjson.JSONObject"%>
<%@page import="com.alibaba.fastjson.JSONArray"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<style type="text/css">
	@IMPORT url("css/core.css");
</style>
<script type="text/javascript" src="js/jquery-1.11.0.js">
</script>
<script type="text/javascript">
	$(function(){
		$(".rule").change(function(){
			var trNode = $(this).parents("tr");
			var ruleId = $(this).val();
			var userId = trNode.find(".cls_uid").text();
			$.get("UpdateRoleServlet?type=2",{id:userId,rule:ruleId},function(){
				
			});
		});
		
		$(".state").change(function(){
			var trNode = $(this).parents("tr");
			var state = $(this).val();
			var userId = trNode.find(".cls_uid").text();
			$.get("UpdateRoleServlet?type=1",{id:userId,state:state},function(){
				
			});
		});
	});
</script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
	<table>
		<thead>
			<tr>
				<th>用户名称</th>
				<th>角色</th>
				<th>操作</th>
			</tr>
		</thead>
		<tbody>
	<%
		Object object = request.getAttribute("list");
		if(object != null && object instanceof JSONArray){
			JSONArray array = (JSONArray)object;
			for(Object obj:array){
				JSONObject jsonObject = (JSONObject)obj;
				//用户的角色
				int rule = jsonObject.getIntValue("rule");
				//用户的状态
				int state = jsonObject.getIntValue("state");
				
	%>
		<tr>
		<td class="cls_uid" style="display: none;"><%=jsonObject.getString("id") %></td>
		<td><%=jsonObject.getString("uname")%></td>
		<td>
		<select class="rule">
			<option value="1" <%if(rule==1)out.print("selected=\"selected\""); %>>管理员</option>
			<option value="0" <%if(rule==0)out.print("selected=\"selected\""); %>>普通用户</option>
		</select>
		<select class="state">
			<option value="1" <%if(state==1)out.print("selected=\"selected\""); %>>有效</option>
			<option value="0" <%if(state==0)out.print("selected=\"selected\""); %>>无效</option>
		</select>
		</td>
		<td>修改</td>
		</tr>
	<%	
		}
		}
	%>
		</tbody>
	</table>
</body>
</html>